home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 19.zip / BS1 part 19 / Lattice C disk 4.adf / cc_extras / grepdemo.c < prev    next >
C/C++ Source or Header  |  1988-11-07  |  636b  |  38 lines

  1. /**
  2. *
  3. * This file is a simple program that demonstrates the use of the
  4. * functions contained in the grep libraries.
  5. *
  6. **/
  7.  
  8. #include "stdio.h"
  9. #include "pat.h"
  10.  
  11. char *string1 = "^[a-z]+(.*)";
  12. char *string2 = "int";
  13. char buf[256];
  14. PATTERN re_gen();
  15.  
  16. main()
  17. {
  18.    FILE *fp;
  19.    PATTERN p;
  20.  
  21.    if ( (fp = fopen("grepdemo.c","r")) == NULL ) {
  22.     printf("Can't open grepdemo.c\n");
  23.     exit(1);
  24.    }
  25.  
  26.    if ( (p = re_gen(string1)) == NULL ) {
  27.     printf("Can't create pattern p\n");
  28.     exit(1);
  29.    }
  30.  
  31.    while ( fgets(buf,256,fp) != NULL ) {
  32.     if ( re_match(buf,p) >= 0 )
  33.         printf("%s",buf);
  34.     if ( re_smatch(string2,buf) >= 0 )
  35.         printf("%s",buf);
  36.    }
  37. }
  38.